import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Basic

Dialog {
    id: messageBox
    
    // 自定义属性
    property string messageType: "info" // info, warning, error, success, question
    property string messageText: ""
    property string messageTitle: ""
    
    // 窗口属性设置
    modal: true
    closePolicy: Dialog.NoAutoClose
    anchors.centerIn: parent
    width: 400
    height: 200
    
    // 背景设置
    background: Rectangle {
        id: bg
        color: "#ffffff"
        radius: 8
        border.color: {
            switch(messageType) {
            case "info": return "#2196F3"
            case "warning": return "#FFC107"
            case "error": return "#F44336"
            case "success": return "#4CAF50"
            case "question": return "#673AB7"
            default: return "#2196F3"
            }
        }
        border.width: 2
    }

    // 内容区域
    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 20

        RowLayout {
            Layout.alignment: Qt.AlignCenter
            Layout.fillHeight: true
            Layout.fillWidth: true

            Image {
                source: {
                    switch(messageType) {
                    case "info": return "/icons/info.svg"
                    case "warning": return "/icons/warning.svg"
                    case "error": return "/icons/error.svg"
                    case "success": return "/icons/success.svg"
                    case "question": return "/icons/question.svg"
                    default: return "/icons/info.svg"
                    }
                }

                sourceSize.width: 48
                sourceSize.height: 48
                Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
            }

            Label {
                text: messageText
                font.pixelSize: 18
                wrapMode: Text.WordWrap
                Layout.fillWidth: true
                Layout.fillHeight: true
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignLeft
            }
        }

        // 按钮区域
        RowLayout {
            Layout.alignment: Qt.AlignRight | Qt.AlignBottom
            spacing: 10

            Button {
                id: confirmButton
                implicitWidth: 80
                implicitHeight: 30
                text: messageType === "question" ? qsTr("是") : qsTr("确定")
                highlighted: true
                
                background: Rectangle {
                    radius: 4
                    color: {
                        switch(messageType) {
                            case "info": return "#2196F3"
                            case "warning": return "#FFC107"
                            case "error": return "#F44336"
                            case "success": return "#4CAF50"
                            case "question": return "#673AB7"
                            default: return "#2196F3"
                        }
                    }
                    opacity: confirmButton.pressed ? 0.8 : 1
                }
                
                contentItem: Text {
                    text: confirmButton.text
                    color: "#ffffff"
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.pixelSize: 14
                }
                
                onClicked: messageBox.accept()
            }

            Button {
                id: cancelButton
                implicitWidth: 80
                implicitHeight: 30
                text: messageType === "question" ? qsTr("否") : qsTr("取消")
                visible: messageType === "question"
                
                background: Rectangle {
                    radius: 4
                    color: "#f5f5f5"
                    border.color: "#dddddd"
                    border.width: 1
                    opacity: cancelButton.pressed ? 0.8 : 1
                }
                
                contentItem: Text {
                    text: cancelButton.text
                    color: "#333333"
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.pixelSize: 14
                }
                
                onClicked: messageBox.reject()
            }
        }
    }
} 
